$(function () {

        $("#submit").click(function () {

            var returnValue = true;

            var txtName = $("#userNameInput").val();
            var txtPassword = $("#userPasswordInput").val();

            var db = getCurrentDb();

//"SELECT * FROM usertable where username='".$nameInput."'"
//if exists (select * from sysdatabases where name='databaseName')
            db.transaction(function (trans) {
                trans.executeSql("select * from Register where  userName=?", [txtName], function (ts, data) {
                    if (data) {
                        for (var i = 0; i < data.rows.length; i++) {
                            var row =data.rows.item(i);//获取某行数据的json对象
                            if (row.userPassword==txtPassword){
                                alert("登录成功！");
                                returnValue=true;
                                window.location.href="showData.html";
                                return;
                            }
                        }
                        alert("账号或密码错误！");
                        returnValue=false;
                        return;

                    }


                }, function (ts, message) {
                    alert(message);
                    var tst = message;
                });


            });
            return returnValue;
        });
    });

function getCurrentDb() {
    //打开数据库，或者直接连接数据库参数：数据库名称，版本，概述，大小
    var db = openDatabase("myDb", "1.0", "it's to save register data!", 1024 * 1024); ;
    return db;

}

